Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Expression rule for current node and fix getting unique nodes#13

Open
lar-dragon wants to merge 1 commit intoPeekmo:masterfrom
lar-dragon:expression_for_current_node
Open

Expression rule for current node and fix getting unique nodes#13
lar-dragon wants to merge 1 commit intoPeekmo:masterfrom
lar-dragon:expression_for_current_node

Conversation

@lar-dragon
Copy link

Rules with expressions allow select nodes by name and content in Jayway JsonPath implementation. for example:

[
 { "a": { "c": 1, "d": 1 }, "b": { "c": 1, "d": 2 } },
 { "a": { "c": 2, "d": 3 }, "b": { "c": 2, "d": 4 } }
]

rule $..a[?(@.c==2)] selects

[ { "c" : 2, "d" : 3 } ]

This changes add similar behavior and allow getting unique nodes with values by references. The following code becomes valid:

$jsonStore = new JsonStore([
 [ "a"=>[ "c"=>1, "d"=>1 ], "b"=>[ "c"=>1, "d"=>2 ] ],
 [ "a"=>[ "c"=>2, "d"=>3 ], "b"=>[ "c"=>2, "d"=>4 ] ]
]);
// set "d" to 5 only for "a" node witch field "c" equivalent 2
$jsonStore->get('$..a[?(@.c==2)]', true)[0]['d'] = 5;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant